package 数据结构和算法入门计划8月开始;
// https://leetcode-cn.com/problems/string-compression/
public class 压缩字符串4430821 {
    class Solution {
        public int compress(char[] chars) {
            int read = 0, write = 0, feed = 1;
            for (; read < chars.length; read ++, feed ++) {
                if (read == chars.length - 1 || chars[read + 1] != chars[read]) {
                    chars[write++] = chars[read];
                    if (feed != 1) {
                        for (char c : String.valueOf(feed).toCharArray()) {
                            chars[write++] = c;
                        }
                    }
                    feed = 0;
                }
            }
            return write;
        }

    }
}

